<?php
namespace App\Http\Controllers;
use App\Models\Browser;
use Illuminate\Support\Facades\Input;

class BrowserController extends WxBaseController{
    protected $except=['index'];
    //获取浏览者列表
    public function index($model,$id){
        $browsers = Browser::where(['target_id'=>$id,'model'=>$model])->get();
        return $this->apiReturn(true,'success',$browsers);
    }
    //存储浏览者信息
    public function store(){
        $input = request();
        if($this->auth()){
            $params = [
                'model' => $input->model,
                'target_id' => $input->target_id,
                'avatar' => $this->auth()->avatarUrl,
                'wxuser_id'=>$this->auth()->id
            ];
            $brow = Browser::updateOrCreate($params);
            return $this->apiReturn(true,'success',$brow);
        }else{
            return $this->apiReturn(true,'游客浏览');
        }
    }
}